package com.example.ruoyivoicecall.util;

import com.example.ruoyivoicecall.entity.ExtFlowInfoEntity;
import com.example.ruoyivoicecall.entity.NvrFlowActionInfoEntity;
import com.example.ruoyivoicecall.entity.NvrFlowInfoEntity;
import com.example.ruoyivoicecall.entity.VoiceInfoEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;

/**
 * NVR工具类
 */
public class NvrUtil {
    public static Integer SUBFLOW_EXETYPE_EXE = Integer.valueOf(0);
    /*    */
    /*    */
    /*    */
    /* 15 */   public static Integer SUBFLOW_EXETYPE_FORWARD = Integer.valueOf(1);
    /*    */
    /*    */
    /*    */
    /* 19 */   public static Integer SUBFLOW_EXETYPE_NOTEBOOK = Integer.valueOf(2);
    /*    */
    /* 21 */   public static Integer SUBFLOW_EXETARGET_FLOW = Integer.valueOf(0);
    /*    */
    /* 23 */   public static Integer SUBFLOW_EXETARGET_MODULE = Integer.valueOf(1);
    /*    */
    /* 25 */   public static Integer SUBFLOW_EXETARGET_SWITCH = Integer.valueOf(1);
    /*    */
    /* 27 */   public static Integer FLOW_TYPE_GENERIC = Integer.valueOf(1);
    /*    */
    /* 29 */   public static Integer FLOW_TYPE_STARTBYWORKING = Integer.valueOf(2);
    /*    */
    /* 31 */   public static Integer FLOW_TYPE_STARTBYLIFE = Integer.valueOf(3);
    /* 32 */   public static String NO_DATA = "-1";
    /* 33 */   public static String SERVER_ERROR = "-2";
    /* 34 */   public static String PERMISSION_ERROR = "-3";
    /*    */   public static final String GET_NVR_INFO_URL = "Inter/Nvr/getNvrInfo.do";
    // 流程类型常量
//    public static final Integer FLOW_TYPE_STARTBYWORKING = 1;
//    public static final Integer FLOW_TYPE_STARTBYLIFE = 2;
//    public static final Integer SUBFLOW_EXETYPE_NOTEBOOK = 1;
//    public static final Integer SUBFLOW_EXETYPE_EXE = 2;
//    public static final Integer SUBFLOW_EXETYPE_FORWARD = 3;
    
    // 存储流程信息的缓存
    private static Map<String, List<ExtFlowInfoEntity>> flowCache = new HashMap<>();
    private static Map<String, List<VoiceInfoEntity>> voiceCache = new HashMap<>();

    /**
     * 缓存流程列表
     */
    public static void cacheFlowList(String key, List<ExtFlowInfoEntity> flowList) {
        flowCache.put(key, flowList);
    }

    /**
     * 获取缓存的流程列表
     */
    public static List<ExtFlowInfoEntity> getCachedFlowList(String key) {
        return flowCache.get(key);
    }

    /**
     * 缓存语音列表
     */
    public static void cacheVoiceList(String key, List<VoiceInfoEntity> voiceList) {
        voiceCache.put(key, voiceList);
    }

    /**
     * 获取缓存的语音列表
     */
    public static List<VoiceInfoEntity> getCachedVoiceList(String key) {
        return voiceCache.get(key);
    }

    /**
     * 清除缓存
     */
    public static void clearCache() {
        flowCache.clear();
        voiceCache.clear();
    }

    /**
     * 构建流程键名
     */
    public static String buildFlowKey(String type, String id) {
        return type + "_" + id;
    }

    /**
     * 构建语音键名
     */
    public static String buildVoiceKey(String type, String id) {
        return "voice_" + type + "_" + id;
    }

    /**
     * 验证流程信息
     */
    public static boolean validateFlowInfo(NvrFlowInfoEntity flow) {
        if (flow == null) {
            return false;
        }
        return comm.isNotEmpty(flow.getFlowName()) && comm.isNotEmpty(flow.getFlowKey());
    }

    /**
     * 验证动作信息
     */
    public static boolean validateActionInfo(NvrFlowActionInfoEntity action) {
        if (action == null) {
            return false;
        }
        return action.getActionType() != null && comm.isNotEmpty(action.getFlowKey());
    }

    /**
     * 验证语音信息
     */
    public static boolean validateVoiceInfo(VoiceInfoEntity voice) {
        if (voice == null) {
            return false;
        }
        return comm.isNotEmpty(voice.getFileName()) && comm.isNotEmpty(voice.getVoiceName());
    }

    /**
     * 按动作类型筛选动作列表
     */
    public static List<NvrFlowActionInfoEntity> filterActionsByType(List<NvrFlowActionInfoEntity> actionList, Integer actionType) {
        List<NvrFlowActionInfoEntity> filtered = new ArrayList<>();
        if (actionList != null && actionType != null) {
            for (NvrFlowActionInfoEntity action : actionList) {
                if (actionType.equals(action.getActionType())) {
                    filtered.add(action);
                }
            }
        }
        return filtered;
    }

    /**
     * 获取默认流程类型
     */
    public static String getDefaultFlowType() {
        return "NORMAL";
    }

    /**
     * 获取默认动作类型
     */
    public static Integer getDefaultActionType() {
        return 1; // 假设1是默认动作类型
    }
}